<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title></title>
    <script src="__STATIC__/js/jquery.js"></script>
    <script src="__STATIC__/layui/layui.js"></script>
    <script src="__STATIC__/bootstrap-table/js/bootstrap-table.js"></script>
    <script src="__STATIC__/bootstrap-table/js/bootstrap-table-zh-CN.min.js"></script>
    <script src="__STATIC__/bootstrap-table/js/dropdown.js"></script>
    <link rel="stylesheet" href="__STATIC__/bootstrap-table/css/bootstrap-table.min.css">
    <link rel="stylesheet" href="__STATIC__/bootstrap-table/css/bootstrap.css">
    <script type="text/javascript" src="__STATIC__/x-admin/js/xadmin.js"></script>
    <link rel="stylesheet" href="__STATIC__/x-admin/css/font.css">
    <link rel="stylesheet" href="__STATIC__/x-admin/css/xadmin.css">
    <script src="__STATIC__/js/common.js"></script>
</head>
<body>
<div class="x-nav">
      <span class="layui-breadcrumb">
        <a href="#">资源管理</a>
        <a href="#">教学教案</a>
        <a href="#">分类管理</a>
      </span>
    <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" href="javascript:location.reload();" title="刷新">
        <i class="layui-icon" style="line-height:30px">ဂ</i></a>
</div>

<xblock>
    <button class="layui-btn" id="add"><i class="layui-icon"></i>添加父类</button>
</xblock>
<table class="table table-bordered" >
    <tr>
        <th align="center" valign="middle" class="borderright">id号</th>
        <th align="center" valign="middle" class="borderright">分类名称</th>
        <th align="center" valign="middle" class="borderright">排序</th>
        <th align="center" valign="middle" class="borderright">级别</th>
        <th align="center" valign="middle" class="borderright">路径</th>
        <th align="center" valign="middle">操作</th>
    </tr>
    {foreach($info as $val)}
        <tr id="del{$val.id}" >
            <td >{$val.id}</td>
            <td>
                <?php
                    for($i=1;$i<$val['level'];$i++){
                        echo "&nbsp;&nbsp;&nbsp;&nbsp;";
                    }
                ?>
                {if $val['level'] == 1}
                    {$val.title}
                {else/}
                    |-{$val.title}
                {/if}
            </td>
            <td>
                <input type="text" id="sort{$val.id}" onblur="fieldSort({$val.id})" name="sort" value="{$val.sort}">
            </td>
            <td>{$val.level}</td>
            <td>{$val.path}</td>
            <td >
                <a href="/plan_type/add?pid={$val.id}&title={$val.title}&path={$val.path}{$val.id},"><button type="button" class="btn btn-primary btn-xs">添加子类</button></a>&nbsp;&nbsp;
                <a href="#"><button type="button" onclick="edit({$val.id})" class="btn btn-info btn-xs">编辑</button></a>&nbsp;&nbsp;
                <a href="#"><button type="button" onclick="types({$val.id})" class="btn btn-default btn-xs">修改父类</button></a>&nbsp;&nbsp;
                <!--<a href="#"><button type="button" onclick="introduce({$val.id})" class="btn btn-success btn-xs">添加简介</button></a>&nbsp;&nbsp;-->
                <a href="#"><button type="button" onclick="del({$val.id})" class="btn btn-danger btn-xs">删除</button></a>
            </td>
        </tr>
    {/foreach}
</table>
</body>
<script>
    //添加父类
    $("#add").click(function(){
        var url = '/plan_type/parent';
        add(url);
    });
    //删除
    function del(id){
        layer.confirm('你确定要删除吗',{btn:['确定','取消']},function(){
            $.ajax({
                url:"{:url('/plan_type/delete')}",
                data:{
                    id:id
                },
                type:"post",
                dataType:"json",
                success:function(res){
                    if(res.code){
                        layer.msg(res.msg,{icon:1,time:2000},function(){
                            $("#del"+id).remove();
                        });
                    }else{
                        layer.msg(res.msg,{icon:5,time:2000});
                    }
                }
            });
        });
    }
    //编辑
    function edit(id){
        layer.open({
            type:2,
            title:'修改类别',
            area:['400px','350px'],
            content:"{:url('/plan_type/edit')}?id="+id
        });
    }
    //修改父类
    function types(id){
        window.location.href = "{:url('/plan_type/type')}?id="+id;
    }
    //排序
    function fieldSort(id){
        $.ajax({
            url:"{:url('/plan_type/sort')}",
            data:{id:id,sorts:$("#sort"+id).val()},
            type:"post",
            dataType:"json",
            success:function(res) {
                if(res.code){
                    layer.msg(res.msg,{icon:1,time:2000},function(){
                        window.location.reload();
                    })
                }else{
                    layer.msg(res.msg,{icon:5,time:2000});
                }
            }
        })
    }
    //添加简介
    function introduce(id) {
        layer.open({
            type:2,
            title:'添加简介',
            area:['500px','700px'],
            content:"{:url('/plan_type_introduce/index')}?id="+id
        })
    }
</script>
</html>